package com.gyp.utils;


import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;

public class DateTimeUtil {

    public static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");

    public static DateTimeFormatter monthFormatter = DateTimeFormatter.ofPattern("yyyyMM");

    public static LocalDateTime timestamToDatetime(Timestamp timestamp) {
        Instant instant = Instant.ofEpochMilli(timestamp.getTime());
        return LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
    }

    public static LocalDateTime parseTime(String time) {
        return LocalDateTime.parse(time,formatter);
    }

    public static String formatTime(LocalDateTime time){
        return time.format(formatter);
    }

    public static String formatMonth(LocalDate date){
        return date.format(monthFormatter);
    }

}
